﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class wjTrade : System.Web.UI.Page
{
    public string Title, Keywords,Description;
    string strSQL, SQL;
    private int cc;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (Session["wj_User"] == null)
            {
                Response.Redirect("uPassport.aspx");
            }
            else
            {
                WebSiteInfo();
                AdressInfo();
                cart_list();
                //TotalMoney();
                if (Request.QueryString["qx"] == "Cancellation")
                {
                    del_GW();
                }
            }
        }
    }

    public void AdressInfo()
    {
        string G_User = Session["wj_User"].ToString();
        DataTable dt = Class1.ExecSel("select * from wj_User where wj_User='" + G_User + "'");
        user.Text = dt.Rows[0]["wj_User"].ToString();
        //user.Text = dt.Rows[0]["wj_User"].ToString();
        Connecter.Text = dt.Rows[0]["wj_Connecter"].ToString();
        //string wj_Email = dt.Rows[0]["wj_Email"].ToString();
        phone.Text = dt.Rows[0]["wj_Phone"].ToString();
        fax.Text = dt.Rows[0]["wj_Fax"].ToString();
        Mobile.Text = dt.Rows[0]["wj_Mobile"].ToString();
        address.Text = dt.Rows[0]["wj_Address"].ToString();
        ZipCode.Text = dt.Rows[0]["wj_ZipCode"].ToString();
        //string wj_WebUrl = dt.Rows[0]["wj_WebUrl"].ToString();
        QQ.Text= dt.Rows[0]["wj_QQ"].ToString();
    }

    public void WebSiteInfo()
    {
        DataTable dt = Class1.ExecSel("select WS_Title,WS_keywords,WS_description from Site_Config");
        this.Title = Convert.ToString(dt.Rows[0]["WS_Title"]);
        this.Keywords = Convert.ToString(dt.Rows[0]["WS_keywords"]);
        this.Description = Convert.ToString(dt.Rows[0]["WS_description"]);
    }
    public void cart_list()
    {
        if (Session["wj_User"] == null)
        {
            Response.Redirect("uPassport.aspx");
        }
        else
        {
            string G_User = Session["wj_User"].ToString();
            DataTable dt01 = Class1.ExecSel("select wj_User,wj_ID from wj_User where wj_User='" + G_User + "'");
            SqlConnection conn = Class1.DBconnection();
            SQL = "select G_TITLE,G_PRICES,G_AMOUNT,G_UID,G_ID,G_TOTAL  from Cart where G_UID='" + dt01.Rows[0]["wj_ID"].ToString() + "'";
            SqlDataAdapter da = new SqlDataAdapter(SQL, conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataTable dt = ds.Tables[0];
            int g_allamount=0;
            int g_alltotal = 0;
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    int c_amount =Convert.ToInt32( ds.Tables[0].Rows[i]["G_AMOUNT"]);
                    int c_total = 0;
                    if (!string.IsNullOrEmpty(ds.Tables[0].Rows[i]["G_TOTAL"].ToString()))
                    {
                        c_total = Convert.ToInt32(ds.Tables[0].Rows[i]["G_TOTAL"]);
                    }
                        
                    g_allamount = g_allamount + c_amount;
                    g_alltotal = g_alltotal + c_total;
                }
                //this.Repeater1.DataSource = dt;
                //this.Repeater1.DataBind();
            }
            lbCount.Text = g_alltotal.ToString();
            lbSum.Text = g_allamount.ToString();
            this.Repeater1.DataSource = dt;
            this.Repeater1.DataBind();
        }
    }

    public void TotalMoney()
    {
        string G_User = Session["wj_User"].ToString();
        DataTable dt01 = Class1.ExecSel("select wj_User,wj_ID from wj_User where wj_User='" + G_User + "'");
        DataTable dt = Class1.ExecSel("select sum(G_PRICES) as G_PRICES from Cart where G_UID='" + dt01.Rows[0]["wj_ID"].ToString() + "'");
        lbCount.Text = dt.Rows[0]["G_PRICES"].ToString();
       // lbSum.Text = dt.Rows.Count.ToString();
        SqlConnection con = Class1.DBconnection();
        string sqlStr = "select * from Cart where G_UID='" + dt01.Rows[0]["wj_ID"].ToString() + "'";
        SqlDataAdapter da = new SqlDataAdapter(sqlStr, con);
        DataSet ds = new DataSet();
        da.Fill(ds, "g");
        string num = ds.Tables["g"].Rows.Count.ToString();
        lbSum.Text = num;
        da.Dispose();
        ds.Dispose();
        con.Close();
        con.Dispose();
    }

    public void del_GW()//删除信息
    {
        int id = int.Parse(Request.QueryString["gid"]);
        SQL = "delete  Cart where G_ID=" + id;
        Class1.ExecSql(SQL);
        Response.Redirect("wjCart.aspx");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("wj_Delivery.aspx");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (Session["wj_User"] == null)
        {
            Response.Redirect("uPassport.aspx");
        }
        else
        {
            string G_User = Session["wj_User"].ToString();
            DataTable dt01 = Class1.ExecSel("select wj_User,wj_ID from wj_User where wj_User='" + G_User + "'");

            SQL = "delete  Cart where G_UID='" + dt01.Rows[0]["wj_ID"].ToString() + "'";
            Class1.ExecSql(SQL);
            Response.Redirect("wjCart.aspx");
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (Session["wj_User"] == null)
        {
            Response.Redirect("uPassport.aspx");
        }
        else
        {
            //DateTime G_Time = DateTime.Now;
            //string G_User = Session["wj_User"].ToString();
            //DataTable dt = Class1.ExecSel("select * from wj_User where wj_User='" + G_User + "'");
            //string wj_Uid = dt.Rows[0]["wj_ID"].ToString();
            //string wj_User = dt.Rows[0]["wj_User"].ToString();
            //string wj_Connecter = dt.Rows[0]["wj_Connecter"].ToString();
            //string wj_Email = dt.Rows[0]["wj_Email"].ToString();
            //string wj_Phone = dt.Rows[0]["wj_Phone"].ToString();
            //string wj_Fax = dt.Rows[0]["wj_Fax"].ToString();
            //string wj_Mobile = dt.Rows[0]["wj_Mobile"].ToString();
            //string wj_Address = dt.Rows[0]["wj_Address"].ToString();
            //string wj_ZipCode = dt.Rows[0]["wj_ZipCode"].ToString();
            //string wj_WebUrl = dt.Rows[0]["wj_WebUrl"].ToString();
            //string wj_QQ = dt.Rows[0]["wj_QQ"].ToString();

            DateTime G_Time = DateTime.Now;
            //string G_User = Session["wj_User"].ToString();
            //DataTable dt = Class1.ExecSel("select * from wj_User where wj_User='" + G_User + "'");
            //string wj_Uid = uid.Text;
            //string wj_User = user.Text;
            string wj_Connecter = Connecter.Text;
            //string wj_Email = dt.Rows[0]["wj_Email"].ToString();
            string wj_Phone = phone.Text;
            string wj_Fax = fax.Text;
            string wj_Mobile = Mobile.Text;
            string wj_Address = address.Text;
            string wj_ZipCode = ZipCode.Text;
            //string wj_WebUrl = dt.Rows[0]["wj_WebUrl"].ToString();
            string wj_QQ = QQ.Text;

            string GSql = "insert into wjOrder(OR_Connecter,OR_Phone,OR_Fax,OR_Mobile,OR_Address,OR_ZipCode,OR_QQ,OR_Time)values('"  + wj_Connecter + "','"  + wj_Phone + "','" + wj_Fax + "','" + wj_Mobile + "','" + wj_Address + "','" + wj_ZipCode + "','" + wj_QQ + "','" + G_Time + "')";
         
            Class1.ExecSql(GSql);
            Class1.AlertShow("您的信息已提交成功！", "wjCart.aspx");
        }
    }
}
